﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace BuildHelper.Domain
{
    public static class DomainHelper
    {
        static ISessionFactory _SessionFactory;

        public static ISessionFactory SessionFactory
        {
            get { return _SessionFactory; }
            set { _SessionFactory = value; }
        }

        public static Exception LastException
        {
            get;
            private set;
        }

        //public static bool TrySave(this IDomainSaveObject obj, ISession session)
        //{
        //    LastException = null;
        //    bool result = true;
        //    try
        //    {
        //        obj.Save(session);
        //        result = true;
        //    }
        //    catch (Exception ex)
        //    {
        //        LastException = ex;
        //        result = false;
        //    }
        //    return result;
        //}
        public static bool TryCommit(this ITransaction transaction)
        {
            LastException = null;
            bool result = true;
            try
            {
                transaction.Commit();
                result = true;
            }
            catch (Exception ex)
            {
                LastException = ex;
                result = false;
            }
            return result;
        }

    }
}
